home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Best of MacTutor - S…e Code for Volumes 1 to 5
/
The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin
/
Source Code
/
#23 (Aug 87)
/
Basic font menus source
/
ZResources.BAS
< prev
Wrap
BASIC Source File
|
1987-06-19
|
4KB
|
201 lines
REM ZBASIC RESOURCE EXAMPLE
REM ©MacTutor 1987
REM By Dave Kelly
REM IMPORTANT: COMPILE THIS PROGRAM AS
REM AN APPLICATION BEFORE RUNNING!!
REM Resources are used which need to be
REM written to application's own resource file
WINDOW OFF:REM Turn off default window
BREAK ON : REM This line may be deleted after program is debugged.
DEFSTR LONG:DEF MOUSE=-1:COORDINATE WINDOW
REM Routine to convert string resource to a string, given the handle.
LONG FN ReturnString$(SHndl&)
FByte%=PEEK(PEEK LONG(SHndl&))
String$=""
FOR i%=1 TO FByte%
String$=String$+CHR$(PEEK(PEEK LONG(SHndl&)+i%))
NEXT i%
END FN= String$
WINDOW #1,"",(50,100)-(450,300),4 : REM Main window.
False=0:True=NOT(False)
OldFont=0:OldSize=12
REM Setup menus
APPLE MENU "About this application…"
MENU 1,0,1,"File"
MENU 1,1,1,"Quit"
EDIT MENU 2
MENU 3,0,1,"Font"
MENU 4,0,1,"Size"
MENU 4,1,1,"9 Point"
MENU 4,2,1,"10 Point"
MENU 4,3,1,"12 Point"
MENU 4,4,1,"14 Point"
MENU 4,5,1,"18 Point"
MENU 4,6,1,"24 Point"
SizeMenuHandle&=FN GETMHANDLE(4)
FontMenuHandle&=FN GETMHANDLE(3)
CALL ADDRESMENU(FontMenuHandle&,CVI("FONT"))
REM Find out what this application is named…
CurApName=&H910
CurApName$=""
FOR I=1 TO PEEK(CurApName)
CurApName$=CurApName$+CHR$(PEEK(CurApName+I))
NEXT I
REM Open application resource file
Refnum=FN OPENRESFILE(CurApName$)
Errnum=FN RESERROR
LONG IF Errnum<>0
BEEP
PRINT "ERROR # ";Errnum
PRINT"Problem with Application Resource File!"
FOR I=1 TO 1000:NEXT I:END
END IF
StrHnd&=FN GETRESOURCE(CVI("STR "),1000)
REM Setting up string resource to save default font and size
LONG IF StrHnd&=0
Str$="Chicago.12"
StrHnd&=FN NEWSTRING(Str$)
CALL ADDRESOURCE(StrHnd&,CVI("STR "),1000,"")
XELSE
StrHnd&=FN GETSTRING(1000)
END IF
REM Convert default font and size
default$=FN ReturnString$(StrHnd&)
defaultfont$=MID$(default$,1,INSTR(1,default$,".")-1)
Fsize=VAL(MID$(default$,INSTR(1,default$,".")+1))
REM Check default font in Font menu
fontcnt%=FN COUNTMITEMS(FontMenuHandle&)
FOR i=1 TO fontcnt%
CALL GETITEM(FontMenuHandle&,i,item$)
IF item$=defaultfont$ THEN OldFont=i:i=fontcnt%+1
NEXT i
CALL CHECKITEM(FontMenuHandle&,OldFont,True)
REM Check default size in Size menu
sizecnt%=FN COUNTMITEMS(FontMenuHandle&)
FOR i=1 TO sizecnt%
CALL GETITEM(SizeMenuHandle&,i,item$)
sname$=MID$(STR$(Fsize),2)+" Point"
IF item$=sname$ THEN OldSize=i:i=sizecnt%+1
NEXT i
CALL CHECKITEM(SizeMenuHandle&,OldSize,True)
CALL GETFNUM(defaultfont$,Fnum%)
TEXT Fnum%,Fsize,0,0
GOSUB "Display"
ON MENU GOSUB "MenuEvent"
FLUSHEVENTS:MENU ON
REM Loop here until something happens
"Loop"
DO
UNTIL 0
MENU STOP
END
"MenuEvent"
Menunumber=MENU(0):Menuitem=MENU(1)
MENU
SELECT Menunumber
CASE 1
GOSUB "File"
CASE 2
GOSUB "Edit"
CASE 3
GOSUB"Font"
CASE 4
GOSUB"Size"
CASE 255
IF Menuitem=1 THEN GOSUB "About"
GOSUB "Display"
CASE ELSE
END SELECT
RETURN
"About" :REM About menu
WINDOW #2,"",(75,100)-(400,250),-2
TEXT 2,14,1,0
PRINT
PRINT SPACE$(11);"ZBasic™ Resource Sample"
PRINT
TEXT 2,12,0,0
PRINT SPACE$(15);"©MacTutor, 1987 by Dave Kelly"
PRINT
PRINT SPACE$(12);"ZBasic™ Version 4.0 - IT WORKS!!!!"
PRINT
MOUSE ON
DO
UNTIL MOUSE(0)<>0
MOUSE OFF
WINDOW CLOSE #2
GOSUB "Display"
RETURN
"File"
CALL UPDATERESFILE(RefNum)
END
"Edit" : REM Edit menu - used for DA's only
RETURN
"Font" : REM Font menu
CALL CHECKITEM(FontMenuHandle&,OldFont,False)
CALL GETITEM(FontMenuHandle&,Menuitem,FontName$)
CALL CHECKITEM(FontMenuHandle&,Menuitem,True)
CALL GETITEM(FontMenuHandle&,Menuitem,defaultfont$)
CALL GETFNUM(defaultfont$,Fnum%)
IF Menuitem<>OldFont GOSUB "SetResString"
OldFont=Menuitem
GOSUB "Display"
RETURN
"Size" : REM Size menu
CALL CHECKITEM(SizeMenuHandle&,OldSize,False)
CALL CHECKITEM(SizeMenuHandle&,Menuitem,True)
SELECT Menuitem
CASE 1
Fsize=9
CASE 2
Fsize=10
CASE 3
Fsize=12
CASE 4
Fsize=14
CASE 5
Fsize=18
CASE 6
Fsize=24
END SELECT
IF Menuitem<>OldSize GOSUB "SetResString"
OldSize=Menuitem
GOSUB "Display"
RETURN
REM Set string to be saved in string resource
"SetResString"
default$=defaultfont$+"."+MID$(STR$(Fsize),2)
CALL SETSTRING(StrHnd&,default$)
CALL CHANGEDRESOURCE(StrHnd&)
RETURN
"Display" :REM Main screen display
TEXT Fnum%,Fsize,0,0
CLS
PRINT "FONT:";defaultfont$
PRINT "SIZE:";Fsize
PRINT
TEXT ,,1,0
MacTutor$="Read MacTutor™ !!"
REM Center MacTutor string
Pxls%=FN STRINGWIDTH(MacTutor$)
Windwidth%=WINDOW(6)
CALL MOVE((Windwidth%-Pxls%)/2,0)
PRINT MacTutor$
RETURN